<!--
 * @Descripttion: 
 * @Author: cbing
 * @Date: 2019-06-17 09:55:00
 * @LastEditors: cbing
 * @LastEditTime: 2019-09-05 10:05:36
 -->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico"> 
	<link href="__PUBLIC__/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/Huploadify/Huploadify.css"/>
    <script src="__PUBLIC__/admin/js/jquery.min.js?v=2.1.4"></script>
</head>

<script>
{if condition="(!isset($cate_id)) OR (!$cate_id)"}
var url = "{:url('ad/lst')}";
{else/}
var cate_id = {$cate_id};
var url = "/{$Request.module}/ad/poslist/cate_id/"+cate_id;
{/if}
var checkAdname = "{:url('ad/checkAdname')}";
var insertUrl = "{:url('ad/add')}";
</script>

<body class="gray-bg">
<style>
input.error{
	border:1px solid red;
}
span.error{
	padding-top:10px;
	color: #f00;
	font-size:12px;
}
</style>

    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>上传SSL证书</h5>
                    </div>
                    <div class="ibox-content">
                        <form method="post" class="form-horizontal" id="form">

                            <div class="form-group">
                                <label  class="col-sm-2 control-label">SSL密钥(KEY):</label>
                                <div class="col-sm-4">
                                    <div style="margin-bottom:7px; margin-top:5px;">
                                        <img id="images_sfzz" {if condition="!empty($file_key)"} src="__PUBLIC__/admin/img/wj1.png" {else} src="__PUBLIC__/admin/img/wj.png"{/if} width="150" height="100" border="0" />
                                        <br/><button type="button" class="btn btn-danger btn-xs delsfzz"{if condition="!empty($file_key)"}{else} style="display:none;" style="display:none;" {/if}>删除 {$file_key}</button>
                                    </div>
                                    <div id="uploaderInput_sfzz"></div>
                                    <input type="hidden" name="sfzz_pic" value="">
                                </div>
                                <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                            </div>
                            <div class="hr-line-dashed"></div>

                            <div class="form-group">
                                <label  class="col-sm-2 control-label">SSL证书(PEM格式):</label>
                                <div class="col-sm-4">
                                    <div style="margin-bottom:7px; margin-top:5px;">
                                        <img id="images_sfzb" {if condition="!empty($file_pem)"} src="__PUBLIC__/admin/img/wj1.png" {else} src="__PUBLIC__/admin/img/wj.png"{/if} width="150" height="100" border="0" />
                                        <br/><button type="button" class="btn btn-danger btn-xs delsfzb" {if condition="!empty($file_pem)"}{else} style="display:none;" style="display:none;" {/if}>删除 {$file_pem}</button>
                                    </div>
                                    <div id="uploaderInput_sfzb"></div>
                                    <input type="hidden" name="sfzb_pic" value="">
                                </div>
                                <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <!-- 全局js -->
    <script src="__PUBLIC__/admin/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- 自定义js -->
    <script type="text/javascript" src="__PUBLIC__/admin/Huploadify/jquery.Huploadify.js"></script>    
    <script src="__PUBLIC__/admin/js/plugins/layer/layer.min.js"></script>
    <script src="__PUBLIC__/admin/js/plugins/validate/jquery.validate.min.js"></script>	
    <!-- iCheck -->
    <script src="__PUBLIC__/admin/js/plugins/iCheck/icheck.min.js"></script>
    <script src="__PUBLIC__/admin/js/common/ajax.js"></script>

	<script>
    	$(function(){   	    
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });

            //上传图片
            $('#uploaderInput_sfzz').Huploadify({
                uploader : '{:url("Im/setSocket")}',
                method:'post',
                formData:null,//发送给服务端的参数，格式：{key1:value1,key2:value2}
                buttonText : '上传文件',
                removeTimeout: 2000,
                fileTypeDesc:'*.key;',
                fileTypeExts:'*.key;',
                fileObjName: 'file', //上传附件$_FILE标识
                fileSizeLimit : 2048,
                //showUploadedPercent:false,//是否实时显示上传的百分比，如20%
                auto : true, //开启,自动上传
                multi : false, //开启,多选文件
                //开始上传
                onUploadStart:function(file){
                    layer.load(2);
                },
                onUploadSuccess : function(file, data, response) {
                    //解析成json对象
                    eval('var data='+data);
                    if(data.status == 200){
                        $('#images_sfzz').attr('src','__PUBLIC__/admin/img/wj1.png');
                        $('.delsfzz').show();
                        $('.delsfzz').text('删除 '+data.data.file_name);
                        layer.msg(data.mess, {icon: 1,time: 2000});
                    }else{
                        layer.msg(data.mess, {icon: 2,time: 2000});
                    }
                },
                //上传完成后执行的操作
                onUploadComplete:function(file){
                    layer.closeAll('loading');
                },
                //上传错误
                onUploadError : function(file, errorCode, errorMsg, errorString) {
                    layer.msg('文件' + file.name + '上传失败:' + errorString, {icon: 2,time: 2000});
                }
            });

            $('.delsfzz').click(function(){
                $('input[name=sfzz_pic]').val('');
                $('#images_sfzz').attr('src','__PUBLIC__/admin/img/wj.png');
                $('.delsfzz').hide();
            });

            $('#uploaderInput_sfzb').Huploadify({
                uploader : '{:url("Im/setSocket")}',
                method:'post',
                formData:null,//发送给服务端的参数，格式：{key1:value1,key2:value2}
                buttonText : '上传文件',
                removeTimeout: 2000,
                fileTypeDesc:'*.pem;',
                fileTypeExts:'*.pem;',
                fileObjName: 'file', //上传附件$_FILE标识
                fileSizeLimit : 2048,
                //showUploadedPercent:false,//是否实时显示上传的百分比，如20%
                auto : true, //开启,自动上传
                multi : false, //开启,多选文件
                //开始上传
                onUploadStart:function(file){
                    layer.load(2);
                },
                onUploadSuccess : function(file, data, response) {
                    //解析成json对象
                    eval('var data='+data);
                    if(data.status == 200){
                        $('#images_sfzb').attr('src','__PUBLIC__/admin/img/wj1.png');
                        $('.delsfzb').show();
                        $('.delsfzb').text('删除 '+data.data.file_name);
                        layer.msg(data.mess, {icon: 1,time: 2000});
                    }else{
                        layer.msg(data.mess, {icon: 2,time: 2000});
                    }
                },
                //上传完成后执行的操作
                onUploadComplete:function(file){
                    layer.closeAll('loading');
                },
                //上传错误
                onUploadError : function(file, errorCode, errorMsg, errorString) {
                    layer.msg('文件' + file.name + '上传失败:' + errorString, {icon: 2,time: 2000});
                }
            });

            $('.delsfzb').click(function(){
                $('input[name=sfzb_pic]').val('');
                $('#images_sfzb').attr('src','__PUBLIC__/admin/img/wj.png');
                $('.delsfzb').hide();
            });

    	    var icon = "<i class='fa fa-times-circle'></i>&nbsp;&nbsp;";
        	$('#form').validate({
	        	errorElement : 'span',
	        	debug: true,//只验证不提交表单
	            //layer ajax提交表单
	            submitHandler:function(){	            	
	                // 序列化 表单数据 后提交 ，太简洁了
	                post(insertUrl,'POST',$('#form').serialize(),1);
	                return false;
	            },//这是关键的语句，配置这个参数后表单不会自动提交，验证通过之后会去调用的方法
	                
	        	rules:{
	        		ad_name:{
	        			required:true,
		        		remote : {
			        	    url : checkAdname,
			        	    type : 'post',
			        		dataType : 'json',
			        		data : {
			        			ad_name : function () {
			        			    return $('input[name=ad_name]').val();
			        	        }
			        		}
			        	}	        			
	        		},
	        		cate_id:{required:true}
	        	},
	        		
	        	messages:{
	        		ad_name:{
	        			required:icon+'必填',
	        			remote:icon+'广告名称已存在'
	        		},
	        		cate_id:{required:icon+'必选'},
	        	}
            });
      });
    	
      function cl(){
    	  location.href = url;
      }
    </script>

</body>
</html>